/**
 * Created by scenic on 2017/8/10.
 */
import {MeshCreateUtils} from "./MeshCreateUtils";
function Plank(spaceFace) {
    this.id = Plank.prototype.ID++;

    this.spaceFace = spaceFace;

    this.plankMesh = MeshCreateUtils.createDefaultPlank("/GSBuilder/resource/007.jpg");

    //木板的深度/宽度
    this.depth = 0.0;

    //木板的长度
    this.width = 0.0;

    //木板的厚度
    this.thickness = 20.0;

    this.isDoor = false;

    //木板的斜切

    //木板的孔位信息

    //木板再给定方向的偏移
    this.positionOffset = new THREE.Vector3();

}

Plank.prototype = Object.assign({
    ID: 0,
    constructor: Plank,
    getAssociateMesh:function () {
        return this.plankMesh;
    },
    setSize: function (width, depth) {
        this.depth = depth;
        this.width = width;

    },
    setPosition: function (x, y, z) {
        this.x = x;
        this.y = y;
        this.z = z;
    },
    setRotate: function (x, y, z) {
        this.rotateX = x;
        this.rotateY = y;
        this.rotateZ = z;
    },
    isDestroyed: function () {
        return this.mesh && this.mesh.destroyed === true;
    },

    buildInteractive:function (object3d_property) {
        var scope = this;
        
        function update() {
            scope.spaceFace.hostSpace.traverse(function () {
                this.updateSpaceMeshAndFaces();
                this.updateSegment();
                this.updatePlankDimensionWidthDefault();
                this.updatePlankDoor();
            })
        }
        
        //选中一个板件
        object3d_property.appendChild(document.createTextNode("板件厚度"));
        object3d_property.appendChild(Widget.createEditText(20, function (value) {
            scope.thickness = parseFloat(value);
            update();

        }));
        //是否为门板

        object3d_property.appendChild(document.createTextNode("是否为门板"));
        object3d_property.appendChild(Widget.createCheckBox("是否为门板",scope.isDoor,function (door) {
            scope.isDoor = door;
            update();
        }))

    }
});

export {Plank}